kanzi::Mesh Class Reference

Use Mesh::CreateInfo to describe and create meshes. More...

#include <kanzi/core.ui/platform/graphics_backend/gl/mesh.hpp>

Inheritance diagram for kanzi::Mesh:
kanzi::GPUResource kanzi::Resource kanzi::Object kanzi::MetaObject kanzi::PropertyObject

Classes

struct  Bone
 Definition of mesh bone, that is used for mesh skinning. More...
 
struct  Cluster
 Parameters for Mesh::Cluster creation. More...
 
struct  Skeleton
 Skeleton is for animating mesh with bones. More...
 

Public Types

typedef pair< AbstractPropertyType, VariantPropertyEntry
 
typedef vector< PropertyEntryPropertyContainer
 
- Public Types inherited from kanzi::GPUResource
enum  MemoryType { GpuOnly, GpuAndRam, RamOnly }
 Memory upload and RAM preservation strategy for GPU resources. More...
 
- Public Types inherited from kanzi::PropertyObject
typedef intrusive_ptr< AbstractPropertyTypeDescriptor::PropertyStoragePropertyStoragePtr
 
typedef vector< PropertyStoragePtrPropertyStorageContainer
 
typedef PropertyStorageContainer::iterator PropertyStorageIterator
 
typedef PropertyStorageContainer::const_iterator PropertyStorageConstIterator
 
typedef PropertyStorageContainer::reverse_iterator PropertyStorageReverseIterator
 

Public Member Functions

 CreateInfo ()
 Default constructor for mesh create info. More...
 
void bind (size_t clusterIndex, ShaderProgramSharedPtr shaderProgram)
 Prepares a cluster from the mesh for rendering with the specified shader. More...
 
const KzuBoundingVolumegetBoundingVolume () const
 Returns the bounding volume of the mesh. More...
 
size_t getVertexCount () const
 Returns the vertex count of the mesh. More...
 
size_t getVertexAttributeCount () const
 Gets the number of the vertex attributes in the mesh. More...
 
size_t getVertexSize () const
 Gets size of one vertex in bytes. More...
 
const void * getVertexData () const
 Gets raw vertex data. More...
 
size_t getClusterCount () const
 Gets the number of clusters in the mesh. More...
 
size_t getClusterIndexCount (size_t clusterIndex) const
 Gets the number of indices in a specified cluster. More...
 
GraphicsPrimitiveType getClusterPrimitiveType (size_t clusterIndex) const
 Gets the primitive type for the cluster. More...
 
MaterialSharedPtr getClusterMaterial (size_t clusterIndex) const
 Gets the cluster material. More...
 
void setClusterMaterial (size_t clusterIndex, MaterialSharedPtr material)
 Sets the cluster material. More...
 
const uint16_t * getClusterIndexData (size_t clusterIndex) const
 Gets index data for given cluster. More...
 
bool updateBoundingBox (Node3D *baseNode, const KzcDynamicArray *transformedObjectList)
 Updates bounding box of mesh with bones from given model. More...
 
size_t getBoneCount () const
 Gets number of bones in mesh. More...
 
Node3DgetBoneNode (size_t boneIndex) const
 Gets node for bone. More...
 
Node3DgetBoneChildJoint (size_t boneIndex) const
 Gets child node for skeletal animation bone. More...
 
void attach (Node *baseNode)
 Attaches a root node for bone node lookup functions. More...
 
void detach ()
 Detaches root node, making bone node lookups no longer available. More...
 
const vector< int > & acquireAttributeMap (ShaderProgramSharedPtr shaderProgram)
 Gets attribute map for given shader program. More...
 
void applySkeleton (Node *baseNode, const KzcDynamicArray *transformedObjectList)
 Applies bone animation, updating matrix palette transformation uniforms. More...
 
const MeshVertexAttributegetVertexAttribute (int index) const
 Gets mesh vertex attribute with given mesh attribute index. More...
 
void bindAttribute (Renderer *renderer, unsigned int shaderAttributeIndex, int meshVertexAttributeIndex)
 Takes one mesh vertex attribute from mesh and makes it usable with (current) shader. More...
 
unsigned int bindAttributes (ShaderProgramSharedPtr shaderProgram)
 Makes all mesh vertex attributes available with a shader program. More...
 
void bindIndices (size_t clusterIndex)
 Makes mesh cluster indices available to the next draw call. More...
 
- Public Member Functions inherited from kanzi::GPUResource
virtual ~GPUResource () KZ_OVERRIDE
 
void invalidate ()
 Notify resource that graphics context was lost and all GPU resources are invalid. More...
 
unsigned int getGPUMemoryUsage () const
 
RenderergetRenderer () const
 
bool isDeployed () const
 
- Public Member Functions inherited from kanzi::Resource
KzcMemoryManagergetMemoryManager () const
 
 Resource (Domain *domain, string_view name)
 
virtual ~Resource ()
 
virtual void loadFromKZB (const ResourceLoaderThreadContext *threadContext, KzcInputStream *inputStream, const KzuBinaryFileInfo *file)
 Function for loading the resource from .KZB. More...
 
virtual void unloadOverride ()
 Unload function for resource. Releases all CPU memory taken by the resource except the resource loader. More...
 
virtual unsigned int getCPUMemoryUsage () const
 Function for getting the memory usage of a resource. More...
 
void setKZB (const KzuBinaryDirectory *binaryDirectory, string_view path)
 Set the binary directory and path of the resource. More...
 
const string & getName () const
 Gets the resource name. More...
 
const string & getUrl () const
 Gets the resource URL. More...
 
void setUrl (string_view url)
 Sets the resource URL. More...
 
void setNotLoaded ()
 
bool isFromKZB () const
 
void reload ()
 
void reloadFromKzb (KzcInputStream *inputStream, const KzuBinaryFileInfo *file)
 
void reloadFromKzb (KzbFile &kzbFile, ReadOnlyMemoryFile &file, KzbMemoryParser &parser)
 
void reloadFromFile (string_view filePath)
 
void load ()
 
void unload ()
 
bool isLoaded () const
 
void kzuResourceLoad_private (const ResourceLoaderThreadContext *threadContext)
 Private function for kzuResourceLoad() with specified thread context. More...
 
void kzuResourceFinishLoading_private (const ResourceLoaderThreadContext *threadContext)
 Private function for finishing the loading of the resource. More...
 
bool isKeepAlive () const
 Tells if the resource has keep alive flag set. More...
 
void setKeepAlive (bool keepAlive)
 Sets the keep alive flag. More...
 
- Public Member Functions inherited from kanzi::Object
 Object (Domain *domain)
 
virtual ~Object ()
 
DomaingetDomain () const
 Returns the domain the object belongs to. More...
 
KzuTaskSchedulergetTaskScheduler () const
 Returns the task scheduler of the object. More...
 
KzuMessageDispatchergetMessageDispatcher () const
 Returns the message dispatcher of the object. More...
 
ResourceManagergetResourceManager () const
 Returns the resource manager of the object. More...
 
virtual const MetaclassgetDynamicMetaclass () const KZ_OVERRIDE
 Returns the metaclass of the dynamic type of the object. More...
 
AppliedStyleEntrySharedPtr applyObjectStyle (kanzi::StyleSharedPtr style)
 Applies a style to an object. More...
 
void unapplyObjectStyle (AppliedStyleEntrySharedPtr appliedStyleEntry)
 
void applyObjectStyles ()
 Apply all styles for an object node. More...
 
void unapplyObjectStyles ()
 Unapplies and removes all applied styles. More...
 
- Public Member Functions inherited from kanzi::MetaObject
virtual ~MetaObject ()
 
bool isTypeOf (const Metaclass *objectType) const
 Determines if the type of this object is the given type or derived from it. More...
 
- Public Member Functions inherited from kanzi::PropertyObject
 PropertyObject ()
 
virtual ~PropertyObject ()
 
template<typename DataType >
void setProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Traits::ParameterType value)
 Sets the local value of a property. More...
 
void removeKzbProperties ()
 
template<typename DataType >
PropertyType< DataType >::Traits::ReturnType getProperty (const PropertyType< DataType > &propertyType) const
 Returns the current value of a property. More...
 
template<typename DataType >
optional< typename PropertyType< DataType >::Traits::ReturnType > getOptionalProperty (const PropertyType< DataType > &propertyType) const
 Evaluates the property value in the same way as the overload above but does not default to the value in property metadata if there are no inputs to the property value. More...
 
template<typename DataType >
PropertyType< DataType >::Traits::ReturnType getPropertyBase (const PropertyType< DataType > &propertyType) const
 Returns the current value of a property disregarding modifiers. More...
 
template<typename DataType >
void setAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::Traits::ParameterType value)
 
template<typename DataType >
PropertyType< DataType >::Traits::ReturnType getAbstractProperty (AbstractPropertyType abstractPropertyType) const
 
template<typename DataType >
PropertyType< DataType >::Traits::ReturnType getAbstractPropertyBase (AbstractPropertyType abstractPropertyType) const
 
template<typename DataType >
optional< typename PropertyType< DataType >::Traits::ReturnType > getOptionalAbstractProperty (AbstractPropertyType abstractPropertyType) const
 
void setPropertyFlag (AbstractPropertyType propertyType, uint32_t flag)
 
bool isPropertyFlagSet (AbstractPropertyType propertyType, uint32_t flag) const
 
void clearPropertyFlag (AbstractPropertyType propertyType, uint32_t flag)
 
bool hasValue (AbstractPropertyType propertyType) const
 Evaluates whether there are any inputs into the property value. More...
 
bool hasBaseValue (AbstractPropertyType propertyType) const
 Evaluates whether there are any inputs into the property value, disregarding modifiers. More...
 
bool hasLocalValue (AbstractPropertyType propertyType) const
 Evaluates whether there is a local value set for the property. More...
 
bool hasNonClassValue (AbstractPropertyType propertyType) const
 Evaluates whether there is a value of any precedence higher than class default value set for the property. More...
 
void removeLocalValue (AbstractPropertyType propertyType)
 Removes the local value associated with the property. More...
 
void copyLocalValue (const PropertyObject &other, AbstractPropertyType propertyType)
 Copies local value of single property from another object. More...
 
void copyLocalValues (const PropertyObject &other)
 Copies all local values from another object. More...
 
virtual void onPropertyChanged (AbstractPropertyType propertyType, PropertyNotificationReason reason)
 Virtual function to handle property change notifications. More...
 
template<typename DataType >
void addPropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, PropertyValuePrecedence precedence, void *owner)
 
template<typename DataType >
void removePropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, void *owner)
 
template<typename DataType >
void addPropertyModifier (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner)
 
template<typename DataType >
void removePropertyModifier (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner)
 
void validatePropertyModifiers (AbstractPropertyType propertyType)
 
template<typename DataType >
void addPropertyNotificationHandler (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::NotificationCallback callback, void *owner)
 
template<typename DataType >
void removePropertyNotificationHandler (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::NotificationCallback callback, void *owner)
 
template<typename DataType >
size_t getPropertyNotificationHandlerCount (const PropertyType< DataType > &propertyType)
 Gets number of current notification handlers for given property type. More...
 

Static Public Member Functions

static MeshSharedPtr create (Domain *domain, const CreateInfo &createInfo, string_view name)
 Creates a mesh with specified mesh creation parameters. More...
 
static MeshSharedPtr createSphere (Domain *domain, float radius, unsigned int segmentCount, unsigned int rowCount, string_view name, MaterialSharedPtr material=MaterialSharedPtr())
 Creates a mesh with a sphere shape in a single cluster. More...
 
static MeshSharedPtr createBox (Domain *domain, Vector3 size, string_view name, MaterialSharedPtr material=MaterialSharedPtr())
 Creates a mesh with a box shape in a single cluster. More...
 
static MeshSharedPtr createPlane (Domain *domain, float width, float height, bool invertU, bool invertV, string_view name, MaterialSharedPtr material=MaterialSharedPtr())
 Creates a plane shape. More...
 
static ResourceManager::LoadTaskSharedPtr createLoadTask (string_view name, KzbFile *kzbFile, unique_ptr< ReadOnlyMemoryFile > file)
 
- Static Public Member Functions inherited from kanzi::Object
static const MetaclassgetStaticMetaclass ()
 Returns the metaclass of Object class. More...
 
static PropertyTypeEditorInfoSharedPtr makeEditorInfo ()
 Default implementation that returns empty editor info. More...
 
- Static Public Member Functions inherited from kanzi::MetaObject
static const MetaclassgetStaticMetaclass ()
 Returns the metaclass of Object class. More...
 
static PropertyTypeEditorInfoSharedPtr makeEditorInfo ()
 Default implementation that returns empty editor info. More...
 

Public Attributes

MemoryType memoryType
 Memory type for the texture. More...
 
vector< Mesh::CreateInfo::Cluster > clusters
 Clusters. More...
 
Box boundingBox
 Bounding box for mesh. More...
 
Skeleton skeleton
 Mesh skeleton for bone animations. More...
 
MeshAttributeCollection vertexFormat
 Mesh vertex attributes. More...
 
size_t vertexSize
 Size of one vertex in bytes. This is sum of all mesh vertex attributes sizes. More...
 
size_t vertexCount
 Number of vertices in the mesh. More...
 
vector< bytevertexData
 Vertex buffer data. More...
 
PropertyContainer properties
 Properties to copy to the mesh. More...
 
struct KANZI_API CreateInfo
 

Protected Member Functions

virtual void reloadOverride () KZ_OVERRIDE
 Resource::reloadOverride() implementation. More...
 
virtual void reloadFromKzbOverride (KzcInputStream *inputStream, const KzuBinaryFileInfo *file) KZ_OVERRIDE
 Resource::reloadFromKzbOverride() implementation. More...
 
virtual void reloadFromKzbOverride (KzbFile &kzbFile, ReadOnlyMemoryFile &file, KzbMemoryParser &parser) KZ_OVERRIDE
 Resource::reloadFromKzbOverride() implementation. More...
 
virtual void invalidateOverride () KZ_OVERRIDE
 GPUResource::invalidateOverride() implementation. More...
 
virtual bool isDeployedOverride () const KZ_OVERRIDE
 GpuResource::isDeployed() implementation. More...
 
virtual unsigned int getGPUMemoryUsageOverride () const KZ_OVERRIDE
 GpuResource::getGPUMemoryUsageOverride() implementation. More...
 
 Mesh (Domain *domain, const CreateInfo &createInfo, string_view name)
 
- Protected Member Functions inherited from kanzi::GPUResource
 GPUResource (Domain *domain, string_view name="")
 
- Protected Member Functions inherited from kanzi::Resource
virtual void reloadFromFileOverride (string_view filePath)
 
virtual unsigned int getCPUMemoryUsageOverride () const
 
- Protected Member Functions inherited from kanzi::Object
void initialize ()
 
void onCopy (const Object &other)
 
- Protected Member Functions inherited from kanzi::MetaObject
 MetaObject ()
 
void initialize ()
 
- Protected Member Functions inherited from kanzi::PropertyObject
void addPropertyValueSource (AbstractPropertyTypeDescriptor &descriptor, AbstractPropertyTypeDescriptor::ValueSource *valueSource, PropertyValuePrecedence precedence, void *owner)
 
void removePropertyValueSource (AbstractPropertyTypeDescriptor &descriptor, AbstractPropertyTypeDescriptor::ValueSource *valueSource, void *owner)
 
AbstractPropertyTypeDescriptor::ValueSourceEntrygetTopValueSourceEntry (AbstractPropertyTypeDescriptor::PropertyStorage &propertyStorage) const
 
AbstractPropertyTypeDescriptor::ValueSourceEntrygetTopValueSourceEntry (AbstractPropertyTypeDescriptor &descriptor) const
 
AbstractPropertyTypeDescriptor::ValueSourcegetTopValueSource (AbstractPropertyTypeDescriptor &descriptor) const
 
AbstractPropertyTypeDescriptor::ValueSourcegetFinalValueSource (AbstractPropertyTypeDescriptor &descriptor) const
 
AbstractPropertyTypeDescriptor::ValueSourcegetNonClassValueSource (AbstractPropertyTypeDescriptor &descriptor) const
 
AbstractPropertyTypeDescriptor::ValueSourcegetClassValueSource (AbstractPropertyTypeDescriptor &descriptor) const
 
AbstractPropertyTypeDescriptor::ValueSourceEntryfindLocalValueSourceEntry (AbstractPropertyTypeDescriptor::PropertyStorage &propertyStorage)
 
AbstractPropertyTypeDescriptor::ValueSourceEntryconstructLocalValueSourceEntry (AbstractPropertyTypeDescriptor &descriptor, AbstractPropertyTypeDescriptor::PropertyStorage &propertyStorage)
 
AbstractPropertyTypeDescriptor::ValueSourceEntryacquireLocalValueSourceEntry (AbstractPropertyTypeDescriptor &descriptor)
 
AbstractPropertyTypeDescriptor::PropertyStoragefindPropertyStorage (AbstractPropertyTypeDescriptor &descriptor) const
 
PropertyStoragePtr findPropertyStoragePtr (AbstractPropertyTypeDescriptor &descriptor) const
 Gets property storage intrusive pointer that can be used to hold a reference until end of operation. More...
 
PropertyStoragePtr constructPropertyStorage (AbstractPropertyTypeDescriptor &descriptor)
 
PropertyStoragePtr acquirePropertyStorage (AbstractPropertyTypeDescriptor &descriptor)
 
AbstractPropertyTypeDescriptor::ModifierStorageacquireModifierStorage (AbstractPropertyTypeDescriptor &descriptor)
 
AbstractPropertyTypeDescriptor::ModifierStoragefindModifierStorage (AbstractPropertyTypeDescriptor &descriptor)
 
AbstractPropertyTypeDescriptor::NotificationStorageacquireNotificationStorage (AbstractPropertyTypeDescriptor &descriptor)
 
AbstractPropertyTypeDescriptor::NotificationStoragefindNotificationStorage (AbstractPropertyTypeDescriptor &descriptor)
 
AbstractPropertyTypeDescriptorfindPropertyTypeDescriptorByUnqualifiedNameAndDataType (string_view unqualifiedName, PropertyDataType dataType)
 
void validatePropertyModifiersAndNotifyHandlers (PropertyStoragePtr &propertyStorage)
 
void copyLocalValue (const AbstractPropertyTypeDescriptor::PropertyStorage &propertyStorage)
 Copy local value from property storage. More...
 
PropertyStorageContainer::iterator beginPropertyStorage ()
 
PropertyStorageContainer::iterator endPropertyStorage ()
 
virtual void notifyPropertyHandlers (PropertyStoragePtr &propertyStorage, PropertyNotificationReason reason)
 
void onCopy (const PropertyObject &other)
 

Friends

void swap (Mesh &mesh1, Mesh &mesh2)
 

Additional Inherited Members

- Protected Types inherited from kanzi::Object
typedef vector< AppliedStyleEntrySharedPtrAppliedStyleContainer
 Applied style container. More...
 
- Protected Attributes inherited from kanzi::Object
AppliedStyleContainer m_appliedStyles
 Listing of applied styles applied to this object. More...
 

Detailed Description

Use Mesh::CreateInfo to describe and create meshes.

Mesh stores the geometry data for rendering Model3d nodes.

Vertex and index listings define meshes. Indices refer to vertices which define the faces of a mesh.

To define a mesh, you need:

  • Vertex format definition. This definition describes the components that define a vertex. This includes information about the vertex position, texture coordinates, normal, and tangent.
  • List of vertices. Each vertex contains components that the format definition describes.
  • List of indices. Indices describe polygons by referring to each vertex by index. When triangles describe a polygon, three indices describe a triangle. You can use several index listings, each of which uses a material.

In Kanzi a mesh can have at most 65536 vertices, a limit set by GLES2. If you need more vertices, create additional meshes.

Examples

To create a cube mesh:

// Define a CreateInfo structure and set it to keep the data after uploading it to the GPU.
Mesh::CreateInfo createInfo;
createInfo.memoryType = GPUResource::GpuAndRam;
// Describe the format for each vertex. In this example, every vertex has a position in 3D space,
// texture coordinates pointing to 2D texture space, and normal and tangent data in 3D space.
// Add to the vertex format description a three-component position.
// Use the standard Kanzi name kzPosition.
MeshVertexAttribute position("kzPosition", VertexAttribute::SemanticPosition, 0, GraphicsDataTypeSFLOAT32, 3, ~0u);
createInfo.vertexFormat.push_back(position);
// Add to the vertex format description a two-component texture coordinate.
// Texture coordinates enable you to use textures on a mesh.
// Use the standard Kanzi name kzTextureCoordinate0.
MeshVertexAttribute textureCoordinate("kzTextureCoordinate0", VertexAttribute::SemanticTextureCoordinate, 0, GraphicsDataTypeSFLOAT32, 2, ~0u);
createInfo.vertexFormat.push_back(textureCoordinate);
// Add to the vertex format description three-component normals.
// Normals enable you to use lighting on a mesh.
// Use the standard Kanzi name kzNormal.
MeshVertexAttribute normal("kzNormal", VertexAttribute::SemanticNormal, 0, GraphicsDataTypeSFLOAT32, 3, ~0u);
createInfo.vertexFormat.push_back(normal);
// Add to the vertex format description three-component tangents.
// Tangents enable you to use normal maps on a mesh.
// Use the standard Kanzi name kzTangent.
MeshVertexAttribute tangent("kzTangent", VertexAttribute::SemanticTangent, 0, GraphicsDataTypeSFLOAT32, 3, ~0u);
createInfo.vertexFormat.push_back(tangent);
// Now that you added all components to the vertex format description, update the offsets, strides, and vertex size.
// Create a cluster. Two triangles define a face. Since a cube has six faces, you must create 36 indices
// (2 * 3 * 6 = 36). In this example the entire mesh uses a single material, which is why you need only
// one cluster.
Mesh::CreateInfo::Cluster cluster(GraphicsPrimitiveTypeTriangles, 36, material, materialUrl);
createInfo.clusters.push_back(cluster);
// Create the vertices. Four vertices define one face of a cube. Since cube has six faces, you must
// create 24 vertices (4 * 6 = 24). Here you create vertex faces with normals that point to the same
// direction. This makes the faces of a cube appear flat. You cannot reuse vertex positions because the
// normals for each face are separate.
{
createInfo.vertexCount = 24;
unsigned int dataSize = createInfo.vertexCount * createInfo.vertexSize;
createInfo.vertexData.resize(dataSize);
// Define the positions of the cube corners.
// This example first defines the back face, then the front face.
const Vector3 cornerPositions[] =
{
Vector3(1.0f, 1.0f, 1.0f),
Vector3(-1.0f, 1.0f, 1.0f),
Vector3(-1.0f, -1.0f, 1.0f),
Vector3(1.0f, -1.0f, 1.0f),
Vector3(1.0f, -1.0f, -1.0f),
Vector3(1.0f, 1.0f, -1.0f),
Vector3(-1.0f, 1.0f, -1.0f),
Vector3(-1.0f, -1.0f, -1.0f)
};
// Define vertex indices for all faces.
const Vector2 UVs[] =
{
Vector2(1.0f, 1.0f),
Vector2(0.0f, 1.0f),
Vector2(0.0f, 0.0f),
Vector2(1.0f, 0.0f)
};
// Define vertex indices for all faces.
const unsigned int faceIndices[][4] =
{
// Front.
{ 0, 1, 2, 3 },
// Right.
{ 5, 0, 3, 4 },
// Back.
{ 6, 5, 4, 7 },
// Left.
{ 1, 6, 7, 2 },
// Top.
{ 5, 6, 1, 0 },
// Bottom.
{ 3, 2, 7, 4 }
};
// Define the normals for each face.
const Vector3 faceNormals[] =
{
Vector3(0.0f, 0.0f, 1.0f),
Vector3(1.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, -1.0f),
Vector3(-1.0f, 0.0f, 0.0f),
Vector3(0.0f, 1.0f, 0.0f),
Vector3(0.0f, -1.0f, 0.0f)
};
// Define tangents for each face.
const Vector3 faceTangent[] =
{
Vector3(1.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, -1.0f),
Vector3(-1.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, 1.0f),
Vector3(1.0f, 0.0f, 0.0f),
Vector3(1.0f, 0.0f, 0.0f)
};
uint16_t vertexIndex = 0;
// To generate the vertex data, loop the data arrays you defined above.
for (unsigned int face = 0; face < 6; ++face)
{
// Add two triangles.
vector<uint16_t>& indexData = createInfo.clusters[0].indexData;
unsigned int faceBaseIndex = face * 6;
// The first three vertices of a face define the first triangle...
indexData[faceBaseIndex + 0] = vertexIndex + 0;
indexData[faceBaseIndex + 1] = vertexIndex + 1;
indexData[faceBaseIndex + 2] = vertexIndex + 2;
// ...and the second triangle uses the two last vertices of the face with the first vertex.
// These two triangles create a quad.
indexData[faceBaseIndex + 3] = vertexIndex + 2;
indexData[faceBaseIndex + 4] = vertexIndex + 3;
indexData[faceBaseIndex + 5] = vertexIndex + 0;
// Write vertices for the face.
for (unsigned int faceCorner = 0; faceCorner < 4; ++faceCorner, ++vertexIndex)
{
unsigned int boxCorner = faceIndices[face][faceCorner];
// Write the correct vertex for this corner of each face.
writeVertexAttribute(createInfo, vertexIndex, 0, cornerPositions[boxCorner]);
// UVs for each face are the same.
writeVertexAttribute(createInfo, vertexIndex, 1, UVs[faceCorner]);
// Normal is constant throughout the face.
writeVertexAttribute(createInfo, vertexIndex, 2, faceNormals[face]);
// Tangent is constant throughout the face.
writeVertexAttribute(createInfo, vertexIndex, 3, faceTangent[face]);
}
}
}
// Center the bounding volume in the center of the mesh and set the size of each axis to 1.0f.
createInfo.boundingBox = Box::fromCenterAndSize(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f));
// Create a mesh from the data you defined in the CreateInfo.
MeshSharedPtr mesh = Mesh::create(domain, createInfo, "box");
See also
Mesh

Each mesh has one or more clusters. Each cluster has material and primitives. Primitives are typically triangles, they are stored as vertex data and index data.

You can load a mesh resource from a .kzb file or create it with the Mesh::create() function.

Once Mesh has been created with constructor, all primitive data is uploaded to GPU memory and no longer stored in CPU memory in Mesh.

See also
MeshCreateInfo

Member Typedef Documentation

Constructor & Destructor Documentation

kanzi::Mesh::Mesh ( Domain domain,
const CreateInfo createInfo,
string_view  name 
)
explicitprotected

Member Function Documentation

kanzi::Mesh::CreateInfo ( )
explicit

Default constructor for mesh create info.

static MeshSharedPtr kanzi::Mesh::create ( Domain domain,
const CreateInfo createInfo,
string_view  name 
)
static

Creates a mesh with specified mesh creation parameters.

In order to create a mesh, you will need a Mesh::CreateInfo structure that is filled with mesh creation parameters.

Primitive data (vertex and index data) is always deployed to GPU memory when Mesh is created.

Parameters
domainDomain for the mesh.
createInfoMesh creation parameters.
nameName for the mesh.
Returns
Mesh shared pointer.
static MeshSharedPtr kanzi::Mesh::createSphere ( Domain domain,
float  radius,
unsigned int  segmentCount,
unsigned int  rowCount,
string_view  name,
MaterialSharedPtr  material = MaterialSharedPtr() 
)
static

Creates a mesh with a sphere shape in a single cluster.

Parameters
radiusRadius of the sphere
segmentCountNumber of segments for the shape
rowCountNumber of rows for the shape
materialMaterial pointer for the cluster. If set, leave the materialURL parameter empty.
materialURLResource address for the cluster material. If set, leave material empty.
Returns
Mesh shared pointer.
static MeshSharedPtr kanzi::Mesh::createBox ( Domain domain,
Vector3  size,
string_view  name,
MaterialSharedPtr  material = MaterialSharedPtr() 
)
static

Creates a mesh with a box shape in a single cluster.

Parameters
widthWidth of the box (size along the x axis)
heightHeight of the box (size along the y axis)
depthDepth of the box (size along z axis)
materialMaterial pointer for the cluster. If set, leave the materialURL parameter empty.
materialURLResource address for the cluster material. If set, leave the material parameter empty.
Returns
Mesh shared pointer.
static MeshSharedPtr kanzi::Mesh::createPlane ( Domain domain,
float  width,
float  height,
bool  invertU,
bool  invertV,
string_view  name,
MaterialSharedPtr  material = MaterialSharedPtr() 
)
static

Creates a plane shape.

Parameters
widthWidth of the plane (size along the x axis)
heightHeight of the plane (size along the y axis)
invertUIf true, the first texture coordinate is inverted
invertVIf true, the second texture coordinate is inverted
materialMaterial pointer for the cluster. If set, leave the materialURL parameter empty.
materialURLResource address for the cluster material. If set, leave the material parameter empty.
Returns
Mesh shared pointer.
void kanzi::Mesh::bind ( size_t  clusterIndex,
ShaderProgramSharedPtr  shaderProgram 
)

Prepares a cluster from the mesh for rendering with the specified shader.

Parameters
clusterIndexWhich cluster to render.
shaderProgramWhich ShaderProgram to render with.
const KzuBoundingVolume* kanzi::Mesh::getBoundingVolume ( ) const

Returns the bounding volume of the mesh.

Returns
Bounding volume for the mesh.
size_t kanzi::Mesh::getVertexCount ( ) const
inline

Returns the vertex count of the mesh.

Returns
Number of vertices in mesh.
size_t kanzi::Mesh::getVertexAttributeCount ( ) const
inline

Gets the number of the vertex attributes in the mesh.

Returns
Number of vertex attributes in mesh.
size_t kanzi::Mesh::getVertexSize ( ) const
inline

Gets size of one vertex in bytes.

Returns
Size of vertex in bytes.
const void* kanzi::Mesh::getVertexData ( ) const
inline

Gets raw vertex data.

User is responsible for casting the data to proper format for reading.

Returns
Raw vertex data or 0 if data was not preserved in RAM.
size_t kanzi::Mesh::getClusterCount ( ) const
inline

Gets the number of clusters in the mesh.

Returns
Number of clusters in the mesh.
size_t kanzi::Mesh::getClusterIndexCount ( size_t  clusterIndex) const

Gets the number of indices in a specified cluster.

Parameters
clusterIndexWhich cluster to query
Returns
Number of indices in the cluster.
GraphicsPrimitiveType kanzi::Mesh::getClusterPrimitiveType ( size_t  clusterIndex) const

Gets the primitive type for the cluster.

Parameters
clusterIndexWhich cluster to query
Returns
The primitive type for the cluster.
MaterialSharedPtr kanzi::Mesh::getClusterMaterial ( size_t  clusterIndex) const

Gets the cluster material.

Parameters
clusterIndexWhich cluster to query
Returns
The material for the cluster.
void kanzi::Mesh::setClusterMaterial ( size_t  clusterIndex,
MaterialSharedPtr  material 
)

Sets the cluster material.

Parameters
clusterIndexThe cluster for which to set the material
materialThe material to apply to the cluster
const uint16_t* kanzi::Mesh::getClusterIndexData ( size_t  clusterIndex) const

Gets index data for given cluster.

Parameters
clusterIndexWhich cluster to query
Returns
Raw cluster index data or 0 if data was not preserved in RAM.
bool kanzi::Mesh::updateBoundingBox ( Node3D baseNode,
const KzcDynamicArray transformedObjectList 
)

Updates bounding box of mesh with bones from given model.

Parameters
baseNodeNode from which bones are located from.
transformedObjectListList of transformed objects, from which bones are retrieved from.
Returns
True if mesh is skinned, otherwise false.
size_t kanzi::Mesh::getBoneCount ( ) const

Gets number of bones in mesh.

Returns
number of bones in mesh.
Node3D* kanzi::Mesh::getBoneNode ( size_t  boneIndex) const

Gets node for bone.

The node is looked up from the latest node that was attached to the mesh with attach() function.

See also
attach()
Parameters
boneIndexindex of bone.
Returns
Node for bone.
Node3D* kanzi::Mesh::getBoneChildJoint ( size_t  boneIndex) const

Gets child node for skeletal animation bone.

The node is looked up from the latest node that was attached to the mesh with attach() function.

See also
attach()
Parameters
boneIndexindex of bone.
Returns
Node for bone.
void kanzi::Mesh::attach ( Node baseNode)

Attaches a root node for bone node lookup functions.

See also
getBoneNode()
getBoneChildJoint()
Parameters
baseNodeRoot node for bone node lookups.
void kanzi::Mesh::detach ( )

Detaches root node, making bone node lookups no longer available.

See also
attach()
const vector<int>& kanzi::Mesh::acquireAttributeMap ( ShaderProgramSharedPtr  shaderProgram)

Gets attribute map for given shader program.

In attribute map keys to are mesh attribute indices and values are shader attribute indices.

Parameters
shaderProgramShader program.
Returns
Attribute map (mesh attribute index -> shader attribute index).
void kanzi::Mesh::applySkeleton ( Node baseNode,
const KzcDynamicArray transformedObjectList 
)

Applies bone animation, updating matrix palette transformation uniforms.

Parameters
baseNodeRoot node for bones.
transformedObjectListTransformed nodes.
const MeshVertexAttribute& kanzi::Mesh::getVertexAttribute ( int  index) const

Gets mesh vertex attribute with given mesh attribute index.

Parameters
indexMesh vertex attribute index.
Returns
Mesh vertex attribute.
void kanzi::Mesh::bindAttribute ( Renderer renderer,
unsigned int  shaderAttributeIndex,
int  meshVertexAttributeIndex 
)

Takes one mesh vertex attribute from mesh and makes it usable with (current) shader.

Parameters
rendererRenderer.
shaderAttributeIndexShader attribute index. This is the target, where attribute data is directed.
meshVertexAttributeIndexMesh attribute index. This is the source, where attibute data is taken from.
unsigned int kanzi::Mesh::bindAttributes ( ShaderProgramSharedPtr  shaderProgram)

Makes all mesh vertex attributes available with a shader program.

Parameters
shaderProgramShader program
Returns
Bitfield: nth bit indicates that nth shader attribute was sourced from the mesh.
void kanzi::Mesh::bindIndices ( size_t  clusterIndex)

Makes mesh cluster indices available to the next draw call.

Parameters
clusterIndexIndex of cluster to prepare.
static ResourceManager::LoadTaskSharedPtr kanzi::Mesh::createLoadTask ( string_view  name,
KzbFile kzbFile,
unique_ptr< ReadOnlyMemoryFile file 
)
static
virtual void kanzi::Mesh::reloadOverride ( )
protectedvirtual

Resource::reloadOverride() implementation.

Reimplemented from kanzi::Resource.

virtual void kanzi::Mesh::reloadFromKzbOverride ( KzcInputStream inputStream,
const KzuBinaryFileInfo file 
)
protectedvirtual

Resource::reloadFromKzbOverride() implementation.

Reimplemented from kanzi::Resource.

virtual void kanzi::Mesh::reloadFromKzbOverride ( KzbFile kzbFile,
ReadOnlyMemoryFile file,
KzbMemoryParser parser 
)
protectedvirtual

Resource::reloadFromKzbOverride() implementation.

Reimplemented from kanzi::Resource.

virtual void kanzi::Mesh::invalidateOverride ( )
protectedvirtual

GPUResource::invalidateOverride() implementation.

Reimplemented from kanzi::GPUResource.

virtual bool kanzi::Mesh::isDeployedOverride ( ) const
protectedvirtual

GpuResource::isDeployed() implementation.

Implements kanzi::GPUResource.

virtual unsigned int kanzi::Mesh::getGPUMemoryUsageOverride ( ) const
protectedvirtual

GpuResource::getGPUMemoryUsageOverride() implementation.

Reimplemented from kanzi::GPUResource.

Friends And Related Function Documentation

void swap ( Mesh mesh1,
Mesh mesh2 
)
friend

Member Data Documentation

MemoryType kanzi::Mesh::memoryType

Memory type for the texture.

If Gpu is not included, texture will not be deployed when created. If Ram is not included, texture will not contain images after it has been deployed. Default value is GpuOnly.

See also
MemoryType
vector<Mesh::CreateInfo::Cluster> kanzi::Mesh::clusters

Clusters.

Box kanzi::Mesh::boundingBox

Bounding box for mesh.

Skeleton kanzi::Mesh::skeleton

Mesh skeleton for bone animations.

MeshAttributeCollection kanzi::Mesh::vertexFormat

Mesh vertex attributes.

size_t kanzi::Mesh::vertexSize

Size of one vertex in bytes. This is sum of all mesh vertex attributes sizes.

size_t kanzi::Mesh::vertexCount

Number of vertices in the mesh.

vector<byte> kanzi::Mesh::vertexData

Vertex buffer data.

PropertyContainer kanzi::Mesh::properties

Properties to copy to the mesh.

Currently they are not used.

struct KANZI_API kanzi::Mesh::CreateInfo

The documentation for this class was generated from the following files: